package com.haoan.index.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.haoan.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haoan.common.annotation.Log;
import com.haoan.common.core.controller.BaseController;
import com.haoan.common.core.domain.AjaxResult;
import com.haoan.common.enums.BusinessType;
import com.haoan.index.domain.Place;
import com.haoan.index.service.PlaceService;
import com.haoan.common.utils.poi.ExcelUtil;
import com.haoan.common.core.page.TableDataInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 景区Controller
 *
 * @author autoGen
 * @date 2025-01-03
 */
@Api(value="景区",tags = "景区")
@RestController
@RequestMapping("/index/place")
public class PlaceController extends BaseController
{
    @Resource
    private PlaceService placeService;

    /**
     * 查询景区列表
     */
    @ApiOperation("查询景区列表")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Place place)
    {
        startPage();
        List<Place> list = placeService.selectPlaceList(place);
        return getDataTable(list);
    }

    /**
     * 导出景区列表
     */
    @ApiOperation("导出景区列表")
    @PreAuthorize("@ss.hasPermi('index:place:export')")
    @Log(title = "景区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Place place)
    {
        List<Place> list = placeService.selectPlaceList(place);
        ExcelUtil<Place> util = new ExcelUtil<Place>(Place.class);
        util.exportExcel(response, list, "景区数据");
    }

    /**
     * 获取景区详细信息
     */
    @ApiOperation("获取景区详细信息")
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(placeService.selectPlaceById(id));
    }

    /**
     * 新增景区
     */
    @ApiOperation("新增景区")
    @PreAuthorize("@ss.hasPermi('index:place:add')")
    @Log(title = "景区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Place place)
    {
        return toAjax(placeService.insertPlace(place));
    }

    /**
     * 修改景区
     */
    @ApiOperation("修改景区")
    @PreAuthorize("@ss.hasPermi('index:place:edit')")
    @Log(title = "景区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Place place)
    {
        return toAjax(placeService.updatePlace(place));
    }

    /**
     * 删除景区
     */
    @ApiOperation("删除景区")
    @PreAuthorize("@ss.hasPermi('index:place:remove')")
    @Log(title = "景区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(placeService.deletePlaceByIds(ids));
    }
}
